// ==UserScript==
// @name         MF飞书视频快速分享
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       kimi
// @match        *://*.feishu.cn/minutes/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=feishu.cn
// @grant        none
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js
// @run-at       document-start
// ==/UserScript==

(function() {
  let tip = '飞书视频快速分享';
  console.log(tip, '初始化');
  console.log(tip, 'jQuery版本：', $().jquery);
  jQuery.fn.extend({
    wait: function (selector, func, times, interval) {
      var _times = times || -1, //100次
        _interval = interval || 20, //20毫秒每次
        _self = this,
        _selector = selector, //选择器
        _iIntervalID //定时器id
      if (this.length) {
        //如果已经获取到了，就直接执行函数
        func && func.call(this)
      } else {
        _iIntervalID = setInterval(function () {
          if (!_times) {
            //是0就退出
            clearInterval(_iIntervalID)
          }
          _times <= 0 || _times-- //如果是正数就 --

          _self = $(_selector) //再次选择
          if (_self.length) {
            //判断是否取到
            func && func.call(_self)
            clearInterval(_iIntervalID)
          }
        }, _interval)
      }
      return this
    }
  })
  $().wait('#suite-share-btn', function () {
    console.log(tip, '开始运行')
    $("#suite-share-btn").click();
    console.log(tip, '已分享==1？', $("button.ud__switch-checked").length)
    if($("button.ud__switch-checked").length<1){
        setTimeout(function () {
            $("button[role=switch]").click();
            setTimeout(function () { $("button.confirm-button").click(); }, 500);
        }, 500);
        console.log(tip, '完成运行')
    }else{
        $("#suite-share-btn").click();
        console.log(tip, '忽略运行')
    }
  })

    // Your code here...
})();